package com.sc.controller.property;

import com.sc.domain.Action;
import com.sc.dto.ActionDTO;
import com.sc.dto.ActionPageDTO;
import com.sc.result.PageResult;
import com.sc.result.Result;
import com.sc.service.ActionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@Slf4j
@Api(tags = "物业服务-活动管理")
@RequestMapping("/property/action")
@RequiredArgsConstructor
@CrossOrigin
public class ActionController {
    @Autowired
    private final ActionService actionService;


    @PostMapping("/add")
    @ApiOperation("添加活动")
    public Result addAction(@RequestBody Action action) {
        log.info("添加活动：{}", action);
        actionService.saveAction(action);
        return Result.success();
    }

    @ApiOperation("根据id删除活动")
    @DeleteMapping("/remove/{id}")
    public Result removeAction(@PathVariable Integer id) {
        log.info("根据id删除活动：{}", id);
        actionService.removeById(id);
        return Result.success();
    }

    @ApiOperation("删除多个活动")
    @DeleteMapping("/remove/batch")
    public Result removeBatch(@RequestParam List<Integer> ids) {
        log.info("删除多个活动：{}", ids);
        actionService.removeByIds(ids);
        return Result.success();
    }

    @PutMapping("/modify")
    @ApiOperation("修改活动")
    public Result modifyAction(@RequestBody Action action) {
        log.info("修改活动：{}", action);
        actionService.modifyAction(action);
        return Result.success();
    }

    @ApiOperation("活动分页查询")
    @GetMapping("/page-query")
    public Result<PageResult> pageQuery(ActionPageDTO actionPageDTO) {
        log.info("活动分页查询：{}", actionPageDTO);
        PageResult result = actionService.pageQuery(actionPageDTO);
        return Result.success(result);
    }


    @GetMapping("/query/{id}")
    @ApiOperation("根据id查询活动")
    public Result<Action> queryById(@PathVariable Integer id) {
        log.info("根据id查活动：{}",id);
        return Result.success(actionService.getById(id));
    }
}
